package com.ruoyi.web.controller.market.extend;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.db.domain.CountInfo;
import com.ruoyi.extend.service.ICountInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 *  渠道 A计价统计
 * 
 * @author ruoyi
 * @date 2022-08-11
 */
@Controller
@RequestMapping("/extend/register")
public class RegisterCountController extends BaseController
{
    private String prefix = "extend/register";

    @Autowired
    private ICountInfoService countInfoService;

    @RequiresPermissions("extend:register:view")
    @GetMapping()
    public String count()
    {
        return prefix + "/register";
    }

    /**
     * 查询渠道统计列表
     */
//    @RequiresPermissions("extend:register:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CountInfo countInfo)
    {

        if (StrUtil.isEmpty(countInfo.getDateInfo())){
            LocalDate localDate = LocalDate.now();
            countInfo.setDateInfo(localDate.toString());
        }

        // 根据当前用户的信息查询
        SysUser sysUser = getSysUser();

        // 如果用户只有【A注册】有角色权限
            // 则查询渠道绑定的用户的信息

        // 如果拥有管理员权限（暴露数据管理员）权限
            // 则，查询所有渠道的数据

        List<Map<String, Object>> mapList = countInfoService.selectCountInfoOutSideMap(sysUser, countInfo);
        return getDataTable(mapList);
    }

}
